﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RN.ERP.DAL.Context;
using System.Data.SqlClient;
using RN.ERP.Entity;


namespace RN.ERP.ZbdlryDAL
{
    public class KaoHeDAL
    {
        private ZBDL_Context zbdlcontext = new ZBDL_Context();

        public Dictionary<string, double> GetCorpDeDuckList(string corpGuids, string areaCode)
        {
            string sql = String.Format(@"SELECT CorpUserGuid, SUM(score) as SumScore  
                                         from v_e_DeDuck    
                                         where CorpUserGuid in ({0}) 
                                         AND bFlowStatus  like '1,%'   
                                         GROUP BY CorpUserGuid ", corpGuids);

            return zbdlcontext.Database.SqlQuery<RN.ERP.Entity.KeyValue>(sql).ToDictionary(a => a.Key, a => double.Parse(a.Value));

        }

        /// <summary>
        /// 主管端导出信用评价实际初审意见汇总表
        /// </summary>
        /// <param name="flowCode"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public List<CorpSnapEvaluationScore_zbdl> GetCorpSnapEvaluationScoreSum(string startDate, string endDate, string appId, string corpRoleId, string cityRoleId, string areaCode)
        {
            SqlParameter[] parameters = new SqlParameter[]{
              new SqlParameter("@SDate",startDate),
              new SqlParameter("@EndDate",endDate),
              new SqlParameter("@AppId",appId),
              new SqlParameter("@AreaCode",areaCode),
              new SqlParameter("@CorpRoleId",corpRoleId),
              new SqlParameter("@CityRoleId",cityRoleId)
            };
            string sql = "EXEC GetCorpSnapEvaluationScoreSum @SDate,@EndDate,@AppId,@AreaCode,@CorpRoleId,@CityRoleId";
            return zbdlcontext.Database.SqlQuery<CorpSnapEvaluationScore_zbdl>(sql, parameters).ToList();
         }
    }
}
